package com.karry.mapper;


import com.karry.pojo.DianZan;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DianZanMapper {

    //查询全部点赞
    @Select("select * from tb_dian_zan where d_status = 1;")
    @ResultMap("dianZanResultMap")
    List<DianZan> searchAllDianZan();


    //查询某一篇文章点赞数量
    @Select("select count(*) from tb_dian_zan where d_blog_id = #{id} and d_status = 1;")
    int selectBlogDianZanCount(int id);


    //查询某个人是否点赞某篇文章
    @Select("select count(*) from tb_dian_zan where d_blog_id = #{blogID} and d_user_id = #{userID} and d_status = 1;")
    int selectUserDianZanBlogStatus(@Param("blogID") int blogId, @Param("userID") int userId);

    //查询点赞过（只要点过不管现在状态）某篇文章
    @Select("select count(*) from tb_dian_zan where d_blog_id = #{blogID} and d_user_id = #{userID};")
    int selectUserDianZanBlogRecordStatus(@Param("blogID") int blogId, @Param("userID") int userId);


    //点赞1（表内没有该条记录）
    @Insert("insert into tb_dian_zan (d_blog_id, d_user_id) values (#{blogID}, #{userID});")
    int dianZanOne(@Param("blogID") int blogId, @Param("userID") int userId);


    //点赞2（表内有该记录但是状态为取消）
    @Update("update tb_dian_zan set d_status = 1 where d_blog_id = #{blogID} and d_user_id = #{userID};")
    int dianZanTwo(@Param("blogID") int blogId, @Param("userID") int userId);


    //取消点赞
    @Update("update tb_dian_zan set d_status = 0 where d_blog_id = #{blogID} and d_user_id = #{userID};")
    int cancelDianZan(@Param("blogID") int blogId, @Param("userID") int userId);

}
